//! \file escape.hpp
//! \brief Purewell Library Escape Encoder/Decoder Header
//! \author Yubin Lim (purewell@gmail.com)
//! \since 2009-11-26

#ifndef __PWHDR_ESCAPE_HPP__
#define __PWHDR_ESCAPE_HPP__

namespace purewell
{

//! \brief Escape encoder/decoer
class PWEscape
{
public:
	//! \brief Encode stream.
	//! \param[out] os Output stream.
	//! \param[in] is Input stream.
	//! \param[in] e Escape character.
	//! \return Output stream reference.
	std::ostream& encode(std::ostream& os, std::istream& is,
		char e='\\') const;

	//! \brief Encode block.
	//! \param[out] obuf Output buffer. It's would be 2 times of input
	//! buffer length.
	//! \param[in] ibuf Input buffer.
	//! \param[in] iblen Input buffer length.
	//! \param[in] e Escape character.
	//! \return Output buffer length.
	size_t encode(char* obuf, const char* ibuf, size_t iblen,
		char e='\\') const;

	//! \brief Decode stream.
	//! \param[out] os Output stream.
	//! \param[in] is Input stream.
	//! \param[in] e Escape character.
	//! \return Output stream reference.
	std::ostream& decode(std::ostream& os, std::istream& is,
		char e='\\') const;

	//! \brief Decode block.
	//! \param[out] obuf Output buffer.
	//! \param[in] ibuf Input buffer.
	//! \param[in] iblen Input buffer length.
	//! \param[in] e Escape character.
	//! \return Output buffer length.
	size_t decode(char* obuf, const char* ibuf, size_t iblen,
		char e='\\') const;

public:
	//! \brief Get instance.
	//! \return Instance reference.
	static PWEscape& getInstance(void);

private:
	explicit PWEscape();
	inline PWEscape& operator = (const PWEscape&) { return *this; }

};

//! \brief Global Escape encoder/decoder instance.
extern PWEscape& gPWEscape;

};//namespace purewell

#endif//!__PWHDR_ESCAPE_HPP__

